<html>
<head><meta charset="utf-8"><title>Continuation of #52234 discussion · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Continuation.20of.20.2352234.20discussion.html">Continuation of #52234 discussion</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="190321586"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Continuation%20of%20%2352234%20discussion/near/190321586" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Chase Wilson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Continuation.20of.20.2352234.20discussion.html#190321586">(Mar 11 2020 at 19:29)</a>:</h4>
<p><span class="user-mention" data-user-id="123856">@Vadim Petrochenkov</span> This works, but isn't really ergonomic for users, as they have to manually import the internal macro</p>
<div class="codehilite"><pre><span></span><span class="k">mod</span> <span class="nn">macros</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">macro_rules</span><span class="o">!</span><span class="w"> </span><span class="n">meta_macro</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="p">()</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="cp">#[macro_export]</span><span class="w"></span>
<span class="w">            </span><span class="n">macro_rules</span><span class="o">!</span><span class="w"> </span><span class="n">created</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">                </span><span class="p">()</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">};</span><span class="w"></span>
<span class="w">            </span><span class="p">}</span><span class="w"></span>
<span class="w">        </span><span class="p">};</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>

<span class="w">    </span><span class="n">meta_macro</span><span class="o">!</span><span class="p">();</span><span class="w"></span>

<span class="w">    </span><span class="cp">#[macro_export]</span><span class="w"></span>
<span class="w">    </span><span class="n">macro_rules</span><span class="o">!</span><span class="w"> </span><span class="n">consumer</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="p">()</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="n">created</span><span class="o">!</span><span class="p">();</span><span class="w"></span>
<span class="w">        </span><span class="p">};</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>

<span class="w">    </span><span class="c1">// Works here</span>
<span class="w">    </span><span class="n">consumer</span><span class="o">!</span><span class="p">();</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">mod</span> <span class="nn">other</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="c1">// Not here, have to manually `use` it</span>
<span class="w">    </span><span class="k">crate</span>::<span class="n">consumer</span><span class="o">!</span><span class="p">();</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>


<p>I also tried to use <code>use $crate::created;</code>, but original error</p>



<a name="190322137"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Continuation%20of%20%2352234%20discussion/near/190322137" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Chase Wilson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Continuation.20of.20.2352234.20discussion.html#190322137">(Mar 11 2020 at 19:34)</a>:</h4>
<p>I also attempted to move the meta-macro's declaration and calling to the root of the crate, but it still produces an error</p>



<a name="190322216"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Continuation%20of%20%2352234%20discussion/near/190322216" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Chase Wilson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Continuation.20of.20.2352234.20discussion.html#190322216">(Mar 11 2020 at 19:35)</a>:</h4>
<p>I understand the reasoning behind the change and I know it's a really specific usecase, but it really hurts library authors trying to do this cleanly</p>



<a name="190327971"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Continuation%20of%20%2352234%20discussion/near/190327971" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Continuation.20of.20.2352234.20discussion.html#190327971">(Mar 11 2020 at 20:31)</a>:</h4>
<p>Well, I certainly agree that it's annoying.</p>



<a name="190328035"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Continuation%20of%20%2352234%20discussion/near/190328035" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Continuation.20of.20.2352234.20discussion.html#190328035">(Mar 11 2020 at 20:31)</a>:</h4>
<p>It's rather a hard-to-fix bug, than a rule that we'd <em>want</em> to be in the language.</p>



<a name="190330019"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Continuation%20of%20%2352234%20discussion/near/190330019" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Chase Wilson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Continuation.20of.20.2352234.20discussion.html#190330019">(Mar 11 2020 at 20:51)</a>:</h4>
<p>Ok, thank you for your help!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>